package com.zookeeper.te1;

import org.apache.zookeeper.*;
import org.apache.zookeeper.data.Stat;

import java.io.IOException;

/**
 * 作者: LCG
 * 日期: 2019/9/16 19:04
 * 描述:
 */
public class TestZookeeper {
    public static void main(String[] args) throws IOException, KeeperException, InterruptedException {

        ZooKeeper zooKeeper=new ZooKeeper("192.168.137.1:2181",5000,new TestWatcher());

        //zooKeeper.exists("/TTT",true);//注册事件  true使用链接注册的watcher

        //zooKeeper.exists("/TTT",new TestWatcher2());

        Stat stat=new Stat();
        byte[] data = zooKeeper.getData("/TTT", new TestWatcher2(), stat);

        System.out.println("-----"+new String(data));

        System.out.println(stat.getCzxid());
        System.out.println(stat.getMzxid());

        zooKeeper.setData("/TTT","9999999999999".getBytes(),-1);

        System.out.println("=========88888=======");
        System.out.println(stat.getCzxid());
        System.out.println(stat.getMzxid());

        byte[] data2 = zooKeeper.getData("/TTT", new TestWatcher2(), stat);

        System.out.println("-----"+new String(data2));

        //zooKeeper.delete("/TTT",-1);

        //zooKeeper.create("/TTT","test".getBytes(),ZooDefs.Ids.OPEN_ACL_UNSAFE,CreateMode.PERSISTENT);

        zooKeeper.close();

    }
}
